home *** CD-ROM | disk | FTP | other *** search
/ Mission 3 / Mission 3.zip / Mission 3.iso / texte / 7up_pd / wirth.c < prev    next >
C/C++ Source or Header  |  1998-10-29  |  4KB  |  187 lines

  1. /* Analysiert öffnende und korrespondierende schlieβende Klammern */
  2. /*****************************************************************************
  3. *
  4. *                                              7UP
  5. *                             Modul: WIRTH.C
  6. *                                     (c) by TheoSoft '90
  7. *
  8. *****************************************************************************/
  9. #include <portab.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <aes.h>
  13.  
  14. #include "7up.h"
  15. #include "forms.h"
  16. #include "windows.h"
  17.  
  18. extern LINESTRUCT *lastwstr;
  19. extern long          lasthfirst,begline, endline;
  20. extern int cut;
  21.  
  22. int Wirth(WINDOW *wp, LINESTRUCT *begcut ,LINESTRUCT *endcut ,char *begstr, char *endstr, long *lc, int *col)
  23. {
  24.    register LINESTRUCT *line;
  25.     register char *cp;
  26.     register int klammer=0, beglen, endlen;
  27.  
  28.     beglen=strlen(begstr);
  29.     endlen=strlen(endstr);
  30.     
  31.    if(wp)
  32.    {
  33.         if(begcut)
  34.            line=begcut;
  35.         else
  36.             line=wp->fstr;
  37.         *lc=(begcut && endcut)?begline:0L;
  38.         while((endcut?(line!=endcut->next):line) && (klammer>=0))
  39.         {
  40.            cp=line->string;
  41.            do
  42.            {
  43.               cp=strstr(cp,begstr);
  44.               if(cp)
  45.               {
  46.                  klammer++;
  47.                  cp+=beglen;
  48.               }
  49.            }
  50.            while(cp);
  51.            cp=line->string;
  52.            do
  53.            {
  54.               cp=strstr(cp,endstr);
  55.               if(cp)
  56.               {
  57.                  klammer--;
  58.                  cp+=endlen;
  59.               }
  60.            }
  61.            while(cp);
  62.            line=line->next;
  63.            (*lc)++;
  64.         }
  65.     }
  66.     (*lc)--;
  67.     *col=0;
  68.     return(klammer);
  69. }
  70.  
  71. int isfreepattern(OBJECT *tree, char *str)
  72. {
  73.     register int i;
  74.     char pattern[11];
  75.  
  76.     if(*str)
  77.     {
  78.         for(i=FREE1BRACE; i<=FREE5BRACE; i+=3)
  79.             if(tree[i].ob_state & SELECTED)
  80.                 if(strstr(form_read(tree,i+1,pattern),str))
  81.                     return(i+1);
  82.     }
  83.     return(FALSE);
  84. }
  85.  
  86. int Wirth2(WINDOW *wp, LINESTRUCT **begcut, LINESTRUCT **endcut, char *begstr, char *endstr)
  87. {
  88.     LINESTRUCT *line,*begcutsave,*endcutsave;
  89.     register char *cp;
  90.     register int begin=0, end=0, beglen, endlen;
  91.     long count=0;
  92.     int i,y,begcolsave,endcolsave;
  93.     
  94.     beglen=strlen(begstr);
  95.     endlen=strlen(endstr);
  96.     
  97.     if(wp)
  98.     {
  99.        line=(*begcut);
  100.        begcutsave=line;
  101.        begcolsave=line->begcol;
  102.  
  103.       if((cp=strstr(line->string,begstr))!=NULL)
  104.            begcolsave=(int)(cp-line->string);
  105.  
  106.        do
  107.        {
  108.            cp=line->string;
  109.            do
  110.            {
  111.               cp=strstr(cp,begstr);
  112.               if(cp)
  113.               {
  114.                  begin++;
  115.                  cp+=beglen;
  116.               }
  117.            }
  118.            while(cp);
  119.            cp=line->string;
  120.            do
  121.            {
  122.               cp=strstr(cp,endstr);
  123.               if(cp)
  124.               {
  125.                  end++;
  126.                  cp+=endlen;
  127.                  endcutsave=line;
  128.                     endcolsave=(int)(cp-line->string);
  129.               }
  130.            }
  131.            while(cp);
  132.            count++;
  133.            line=line->next;
  134.        }
  135.        while(line && begin!=end);
  136.        if(/*line &&*/ begin==end && begin>0 && end>0)
  137.        {
  138.             hide_blk(wp,*begcut,*endcut);
  139.             lastwstr=wp->wstr;
  140.             lasthfirst=wp->hfirst;
  141.             begline=wp->row+wp->hfirst/wp->hscroll;
  142.             endline=begline+count-1; /*19.3.94 eine Zeile zuviel*/
  143.  
  144.             (*begcut)=begcutsave;
  145.             (*endcut)=endcutsave;
  146.             if(*begcut == *endcut)
  147.             {
  148.                 (*begcut)->begcol=begcolsave;
  149.                 (*endcut)->endcol=endcolsave;
  150.             }
  151.             else
  152.             {            
  153.                 (*begcut)->begcol=begcolsave;
  154.                 (*begcut)->endcol=STRING_LENGTH;
  155.                 (*endcut)->begcol=0;
  156.                 (*endcut)->endcol=endcolsave;
  157.             }
  158.             for(line=(*begcut); line != (*endcut)->next; line=line->next)
  159.             {
  160.                 line->attr|=SELECTED;                                         /* attribut setzen */
  161.             }
  162.             if((*begcut) != (*endcut)) /* mehr als eine zeile */
  163.                 for(line=(*begcut)->next; line && line != (*endcut); line=line->next)
  164.                 {
  165.                     line->begcol=0;
  166.                     line->endcol=STRING_LENGTH;
  167.                 }
  168.             graf_mouse(M_OFF,0L);
  169.             Wcursor(wp);
  170.             for(line=wp->wstr,i=0,y=wp->ywork;
  171.                  line && y<(wp->ywork+wp->hwork-1);
  172.                  line=line->next, i++, y+=wp->hscroll)
  173.                 if(line->attr & SELECTED)
  174.                 {
  175.                     mark_line(wp,line,i);
  176.                 }
  177.             Wcuroff(wp);
  178.             Wcursor(wp);
  179. /*
  180.             graf_mouse(M_ON,0L);
  181. */
  182.             return(TRUE);
  183.        }
  184.     }
  185.     return(FALSE);
  186. }
  187.